Passed
Pull Request — master (#47)
by
unknown
05:23
created

toast.js ➔ _interopDefaultLegacy   B

Complexity

Conditions 7

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 1
dl 0
loc 1
rs 8
c 0
b 0
f 0
1
/*!
2
  * Bootstrap toast.js v4.6.0 (https://getbootstrap.com/)
3
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', './util'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Toast = factory(global.jQuery, global.Util));
0 ignored issues
show
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
}(this, (function ($, Util) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
  var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
16
17
  function _defineProperties(target, props) {
18
    for (var i = 0; i < props.length; i++) {
19
      var descriptor = props[i];
20
      descriptor.enumerable = descriptor.enumerable || false;
21
      descriptor.configurable = true;
22
      if ("value" in descriptor) descriptor.writable = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
23
      Object.defineProperty(target, descriptor.key, descriptor);
24
    }
25
  }
26
27
  function _createClass(Constructor, protoProps, staticProps) {
28
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
29
    if (staticProps) _defineProperties(Constructor, staticProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
30
    return Constructor;
31
  }
32
33
  function _extends() {
34
    _extends = Object.assign || function (target) {
0 ignored issues
show
Comprehensibility introduced by
It seems like you are trying to overwrite a function name here. _extends is already defined in line 33 as a function. While this will work, it can be very confusing.
Loading history...
35
      for (var i = 1; i < arguments.length; i++) {
36
        var source = arguments[i];
37
38
        for (var key in source) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
39
          if (Object.prototype.hasOwnProperty.call(source, key)) {
40
            target[key] = source[key];
41
          }
42
        }
43
      }
44
45
      return target;
46
    };
47
48
    return _extends.apply(this, arguments);
49
  }
50
51
  /**
52
   * ------------------------------------------------------------------------
53
   * Constants
54
   * ------------------------------------------------------------------------
55
   */
56
57
  var NAME = 'toast';
58
  var VERSION = '4.6.0';
59
  var DATA_KEY = 'bs.toast';
60
  var EVENT_KEY = "." + DATA_KEY;
61
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
62
  var EVENT_CLICK_DISMISS = "click.dismiss" + EVENT_KEY;
63
  var EVENT_HIDE = "hide" + EVENT_KEY;
64
  var EVENT_HIDDEN = "hidden" + EVENT_KEY;
65
  var EVENT_SHOW = "show" + EVENT_KEY;
66
  var EVENT_SHOWN = "shown" + EVENT_KEY;
67
  var CLASS_NAME_FADE = 'fade';
68
  var CLASS_NAME_HIDE = 'hide';
69
  var CLASS_NAME_SHOW = 'show';
70
  var CLASS_NAME_SHOWING = 'showing';
71
  var DefaultType = {
72
    animation: 'boolean',
73
    autohide: 'boolean',
74
    delay: 'number'
75
  };
76
  var Default = {
77
    animation: true,
78
    autohide: true,
79
    delay: 500
80
  };
81
  var SELECTOR_DATA_DISMISS = '[data-dismiss="toast"]';
82
  /**
83
   * ------------------------------------------------------------------------
84
   * Class Definition
85
   * ------------------------------------------------------------------------
86
   */
87
88
  var Toast = /*#__PURE__*/function () {
89
    function Toast(element, config) {
90
      this._element = element;
91
      this._config = this._getConfig(config);
92
      this._timeout = null;
93
94
      this._setListeners();
95
    } // Getters
96
97
98
    var _proto = Toast.prototype;
99
100
    // Public
101
    _proto.show = function show() {
102
      var _this = this;
103
104
      var showEvent = $__default['default'].Event(EVENT_SHOW);
105
      $__default['default'](this._element).trigger(showEvent);
106
107
      if (showEvent.isDefaultPrevented()) {
108
        return;
109
      }
110
111
      this._clearTimeout();
112
113
      if (this._config.animation) {
114
        this._element.classList.add(CLASS_NAME_FADE);
115
      }
116
117
      var complete = function complete() {
118
        _this._element.classList.remove(CLASS_NAME_SHOWING);
119
120
        _this._element.classList.add(CLASS_NAME_SHOW);
121
122
        $__default['default'](_this._element).trigger(EVENT_SHOWN);
123
124
        if (_this._config.autohide) {
125
          _this._timeout = setTimeout(function () {
126
            _this.hide();
127
          }, _this._config.delay);
128
        }
129
      };
130
131
      this._element.classList.remove(CLASS_NAME_HIDE);
132
133
      Util__default['default'].reflow(this._element);
134
135
      this._element.classList.add(CLASS_NAME_SHOWING);
136
137
      if (this._config.animation) {
138
        var transitionDuration = Util__default['default'].getTransitionDurationFromElement(this._element);
139
        $__default['default'](this._element).one(Util__default['default'].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
140
      } else {
141
        complete();
142
      }
143
    };
144
145
    _proto.hide = function hide() {
146
      if (!this._element.classList.contains(CLASS_NAME_SHOW)) {
147
        return;
148
      }
149
150
      var hideEvent = $__default['default'].Event(EVENT_HIDE);
151
      $__default['default'](this._element).trigger(hideEvent);
152
153
      if (hideEvent.isDefaultPrevented()) {
154
        return;
155
      }
156
157
      this._close();
158
    };
159
160
    _proto.dispose = function dispose() {
161
      this._clearTimeout();
162
163
      if (this._element.classList.contains(CLASS_NAME_SHOW)) {
164
        this._element.classList.remove(CLASS_NAME_SHOW);
165
      }
166
167
      $__default['default'](this._element).off(EVENT_CLICK_DISMISS);
168
      $__default['default'].removeData(this._element, DATA_KEY);
169
      this._element = null;
170
      this._config = null;
171
    } // Private
172
    ;
173
174
    _proto._getConfig = function _getConfig(config) {
175
      config = _extends({}, Default, $__default['default'](this._element).data(), typeof config === 'object' && config ? config : {});
176
      Util__default['default'].typeCheckConfig(NAME, config, this.constructor.DefaultType);
177
      return config;
178
    };
179
180
    _proto._setListeners = function _setListeners() {
181
      var _this2 = this;
182
183
      $__default['default'](this._element).on(EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function () {
184
        return _this2.hide();
185
      });
186
    };
187
188
    _proto._close = function _close() {
189
      var _this3 = this;
190
191
      var complete = function complete() {
192
        _this3._element.classList.add(CLASS_NAME_HIDE);
193
194
        $__default['default'](_this3._element).trigger(EVENT_HIDDEN);
195
      };
196
197
      this._element.classList.remove(CLASS_NAME_SHOW);
198
199
      if (this._config.animation) {
200
        var transitionDuration = Util__default['default'].getTransitionDurationFromElement(this._element);
201
        $__default['default'](this._element).one(Util__default['default'].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
202
      } else {
203
        complete();
204
      }
205
    };
206
207
    _proto._clearTimeout = function _clearTimeout() {
208
      clearTimeout(this._timeout);
209
      this._timeout = null;
210
    } // Static
211
    ;
212
213
    Toast._jQueryInterface = function _jQueryInterface(config) {
214
      return this.each(function () {
215
        var $element = $__default['default'](this);
216
        var data = $element.data(DATA_KEY);
217
218
        var _config = typeof config === 'object' && config;
219
220
        if (!data) {
221
          data = new Toast(this, _config);
222
          $element.data(DATA_KEY, data);
223
        }
224
225
        if (typeof config === 'string') {
226
          if (typeof data[config] === 'undefined') {
227
            throw new TypeError("No method named \"" + config + "\"");
228
          }
229
230
          data[config](this);
231
        }
232
      });
233
    };
234
235
    _createClass(Toast, null, [{
236
      key: "VERSION",
237
      get: function get() {
238
        return VERSION;
239
      }
240
    }, {
241
      key: "DefaultType",
242
      get: function get() {
243
        return DefaultType;
244
      }
245
    }, {
246
      key: "Default",
247
      get: function get() {
248
        return Default;
249
      }
250
    }]);
251
252
    return Toast;
253
  }();
254
  /**
255
   * ------------------------------------------------------------------------
256
   * jQuery
257
   * ------------------------------------------------------------------------
258
   */
259
260
261
  $__default['default'].fn[NAME] = Toast._jQueryInterface;
262
  $__default['default'].fn[NAME].Constructor = Toast;
263
264
  $__default['default'].fn[NAME].noConflict = function () {
265
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
266
    return Toast._jQueryInterface;
267
  };
268
269
  return Toast;
270
271
})));
272
//# sourceMappingURL=toast.js.map
273